package com.example.demo.MyBatis;

import com.example.demo.MyBatis.dao.UserDao;
import com.example.demo.MyBatis.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Author : 叶荻风
 * @create : 2024/5/24 15:09
 */
@Slf4j
public class TestMybatis {
    public static void main(String[] args) throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        log.info("adasd");
        User user = new User();
        user.setName("difeng");
        user.setPassword("123456");
        mapper.save(user);
        sqlSession.commit();

    }
}
